using Moq;
using NUnit.Framework;
using Tycho.Parser.Peg;
using Tycho.Parser.Syntax;

namespace Tycho.Parser.Tests.Syntax {
    [TestFixture]
    public class CaptureSyntaxSpecification {
        [Test]
        public void AccumulateCapturesShouldAddName () {
            string name = "name";

            var accumulator = new CaptureAccumulator();

            new CaptureSyntax (name, null).AccumulateCaptures (accumulator);

            Assert.AreEqual (false, accumulator.Captures[name]);
        }

        [Test]
        public void CompileShouldSetIsFirstToFalse () {
            ProductionLookup productionLookup = new ProductionLookup (null, null, null);
            Assert.IsTrue (productionLookup.IsFirst);
            new CaptureSyntax ("name", null).Compile (productionLookup);
            Assert.IsFalse (productionLookup.IsFirst);
        }

        [Test]
        public void CompileShouldReturnProductionReturnedFromProductionLookup () {
            var lang = new Language ("lang");
            var production = new Mock<Production> ();
            var productionLookup = new ProductionLookup (lang, null, production.Object);
            Assert.AreSame (production.Object, new CaptureSyntax ("name", lang).Compile (productionLookup));
        }
    }
}